<?php
/**
 * @author: Arian
 * @email: arian@dwebsite.com
 * @on: 06/23/08
 *
 */
 Zend_Loader::loadClass("CodesUtility");
 Zend_Loader::loadClass("BaseDBRow");
 class User extends BaseDBRow
 {
	const _tablename = "projecte_trade.users";
 	protected function setUp()
 	{
 		$this->_tableName = self::_tablename;		
 	}
	
	public function exists($username){
		
		$query = new QueryCreator();
		$query->addSelect(" count(u.id) as count");
	    $query->addFrom($this->_tableName . " as u");
		$query->addWhere("u.username = '".addslashes($username) ."' " );
		
		$db = DBCon::instance();
		$result = $db->executeQuery($query->createSQL());
		
		if($result){
			$count = $result[0]['count'];
			if($count > 0){
				return true;
			}
		}
		return false;    
	}
	

	public function loadByPayerID($payerid)
	{
		Zend_Loader::loadClass("Payer");
		if($payerid){
			return $this->loadWhere(" id = ( SELECT p.user_id from ". Payer::_tablename .  " p WHERE p.id = " . $payerid . ") " );
		}
		return 0;
	}
	
	public function loadByStaffId($staffId)
	{
		Zend_Loader::loadClass("Staff");
		if($staffId) {
			return $this->loadWhere(" id = ( SELECT s.user_id from ". Staff::_tablename .  " s WHERE s.id = " . $staffId . ") " );
		}
		return 0;
	}
	
	public function loadbyUsername($username){
		$query = new QueryCreator();
		$query->addSelect(" id,username,user_type_id");
	    $query->addFrom($this->_tableName . " as u");
		$query->addWhere("u.username = '".addslashes($username) ."' " );
		
		$db = DBCon::instance();
		$result = $db->executeQuery($query->createSQL());
		//echo $query->createSQL();
		return $result;

	}
 }
?>